Skip to content

fix(atlas-search): cap search neighbor expansion - #6328

Merged
developing-today[bot] merged 1 commit into
mainfrom
queue/9679-5593-expand-cap
Nov 7, 2026
Merged

developing-today[bot] merged 1 commit into
mainfrom
queue/9679-5593-expand-cap

Conversation

@dezren39

@dezren39 dezren39 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Search expansion now validates the shared 100-neighbor ceiling before any backend work, in the CLI, service, and core API. The core also checks the conversion to the backend's signed neighbor count.

--k remains deliberately unbounded because core truncates it to the bounded candidate set.

Fixes #5593.

Evidence

  • Before: --expand 1000000 was accepted; a single hit could return the full message's neighboring chunks.
  • After: service validation accepts 100 and rejects 101 with HTTP 400; CLI rejects 101 with exit 2 before opening the backend.
  • Tests: cargo test --manifest-path pkgs/atlas-search/Cargo.toml -p atlas-search and cargo test --manifest-path pkgs/atlas-search/Cargo.toml -p atlas-core passed; cargo fmt --manifest-path pkgs/atlas-search/Cargo.toml --all -- --check passed.

Merge Danger

Door: Two-way.

Blast Radius: Low — only oversized expansion requests are rejected.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 5, 2026 17:21
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T04:43:42.012960Z ab0ac12 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues
What changed in this PR

Caps Atlas search neighbor expansion to a shared 100-neighbor ceiling across CLI, service validation, and atlas-core, preventing oversized expansion requests from reaching backend work.

Changes:

  • Added MAX_EXPAND_NEIGHBORS constant to atlas-core and enforced it in core search execution.
  • Updated CLI parsing to reject --expand values above the shared limit (exit 2) and added parity tests.
  • Updated service request validation and added a regression test for the expand limit.
File Description
pkgs/​atlas-search/​crates/​atlas-search/​tests/​cli_parity.rs Adds a CLI regression test ensuring --expand > 100 fails before backend access.
pkgs/​atlas-search/​crates/​atlas-search/​src/​server.rs Enforces expand ceiling in service validator and adds a matching test.
pkgs/​atlas-search/​crates/​atlas-search/​src/​main.rs Applies shared expand max in CLI argument validation and extends unit tests.
pkgs/​atlas-search/​crates/​atlas-core/​src/​search.rs Adds core-side expand cap and makes neighbor count conversion to backend i64 fallible.
pkgs/​atlas-search/​crates/​atlas-core/​src/​lib.rs Introduces MAX_EXPAND_NEIGHBORS constant (set to 100).

Review effort: Lite

"--expand",
args.expand,
0,
Some(atlas_core::MAX_EXPAND_NEIGHBORS as i64),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ab0ac12 (rebase onto current main): the production cast in cmd_search is now i64::try_from(atlas_core::MAX_EXPAND_NEIGHBORS).expect("neighbor cap fits in i64"), so a future oversized constant panics loudly at startup-validation instead of wrapping. — repo-worker-code-r

Comment on lines +773 to +780
// --expand shares the service's 100-neighbor ceiling.
let max_expand = atlas_core::MAX_EXPAND_NEIGHBORS as i64;
assert_eq!(count("--expand", max_expand, 0, Some(max_expand)), Ok(100));
assert_eq!(
count("--expand", max_expand + 1, 0, Some(max_expand)).unwrap_err(),
(
2,
"--expand must be between 0 and 100 (design section 2)".to_string()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept deliberately: Ok(100) and the literal error string pin the bounds ACTUAL value, not just its consistency with the constant. The acceptance criteria for #5593 require the bound justified against the get-chunk 100 cap; if MAX_EXPAND_NEIGHBORS ever changes, this test failing is the intended tripwire that forces re-justification. — repo-worker-code-r

Comment on lines +2497 to +2498
assert!(
err.body.error.message.contains("100"),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept deliberately, same rationale as the CLI test: asserting the literal 100 pins the bound value itself (the #5593 acceptance ties it to the get-chunk cap), so a silent constant change fails here instead of drifting. — repo-worker-code-r

Comment on lines +160 to +162
assert!(
!stderr.contains("missing.db"),
"backend was reached: {stderr}"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept: the missing.db check is a secondary negative assert only — the primary pins are exit code 2 and the exact --expand message, which cannot be produced by any backend path. The backend-open error including the db path is established behavior relied on by the other parity tests in this file. — repo-worker-code-r

@dezren39
dezren39 force-pushed the queue/9679-5593-expand-cap branch from 52befc2 to ab0ac12 Compare November 7, 2026 04:42
@developing-today
developing-today Bot merged commit ac40b67 into main Nov 7, 2026
3 of 5 checks passed
@developing-today
developing-today Bot deleted the queue/9679-5593-expand-cap branch November 7, 2026 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

atlas-search: expand has no upper bound — one hit returns its whole message, bypassing the 100-neighbor cap get-chunk enforces

2 participants